package cn.com.gridinfo.sooc.core.course.info.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;
import cn.com.gridinfo.sooc.core.course.info.adapter.ProcessAdapter;
import cn.com.gridinfo.sooc.core.course.note.common.CodeConst;
import cn.com.gridinfo.sooc.core.course.note.dao.CourseDao;
import cn.com.gridinfo.sooc.utils.IntentUtil;
import cn.com.gridinfo.sooc.utils.MessageUtils;
import cn.com.gridinfo.sooc.utils.widget.UnScrollGridView;
import cn.com.gridinfo.sooc.utils.widget.UnScrollListView;

/**
 * 结课标准
 * Created by 11299 on 2016/8/9.
 */
public class CourseStandActivity extends BaseSoocActivity {

    @InjectView(R.id.title)
    TextView title;//顶部内容标题
    CourseDao dao;
    @InjectView(R.id.processList)
    UnScrollListView processList;//学习进度
    @InjectView(R.id.standList)
    UnScrollGridView standList;//结课标准
    ProcessAdapter adapter;//适配器
    @InjectView(R.id.lookdiploma)
    Button lookdiploma;//查看证书按钮

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course_stand);
        ButterKnife.inject(this);
        dao = new CourseDao(this);
        //获取结课标准
        dao.courseStand(getIntent().getStringExtra("kcid"));
    }

    /**
     * 学习进度布局初始化
     */
    void initProcess() {
        adapter = new ProcessAdapter(dao.getCourseProcessList(), this, 2);
        processList.setAdapter(adapter);
    }

    /**
     * 结课标准布局初始化
     */
    void initStand() {
        adapter = new ProcessAdapter(dao.getCourseProcessList(), this, 1);
        standList.setAdapter(adapter);
    }

    @Override
    public void onRequestSuccess(int requestCode) {
        try {
            if (dao.getStatus().equals("0")) {
                switch (requestCode) {
                    case CodeConst.COURSE_STAND:
                        //结课标准
                        //是否加入课程
                        if (dao.getIsJoin().equals("1")) {
                            //是
                            title.setText("课程学习进度 : ");
                            initProcess();
                            standList.setVisibility(View.GONE);
                            lookdiploma.setVisibility(View.VISIBLE);
                            //是否有结业证书
                            if (dao.getHasCertificate().equals("1")) {
                                //是
                            } else {
                                lookdiploma.setEnabled(false);
                                lookdiploma.setText("未获得证书");
                            }
                        } else {
                            title.setText("获取该课程结业证书的标准如下 : ");
                            initStand();
                            processList.setVisibility(View.GONE);
                        }
                        break;
                }
            } else {
                MessageUtils.showImageShortToast(this, dao.getStatusCode());
            }
        } catch (Exception e) {
            MessageUtils.showImageShortToast(this, "数据请求异常");
        }
    }

    /**
     * 查看结业证书点击
     */
    @OnClick(R.id.lookdiploma)
    void onClick() {
        IntentUtil.intentSlidIn(this, CompleteDiplomaActivity.class, 00);
    }

    @Override
    public String setupToolBarTitle() {
        return "结课标准";
    }

    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }

    @OnClick(R.id.toolbar_leftbtn)
    void goBack() {
        finish();
    }
}
